<template>

  <div>
    <LeftCommon></LeftCommon>
    <div class="layout">
    <Layout>
      <Header>
        <Menu mode="horizontal" theme="dark" active-name="1">
         <!--
          <div class="layout-nav">
            <MenuItem name="1">
              <Icon type="ios-navigate"></Icon>
              Item 1
            </MenuItem>
            <MenuItem name="2">
              <Icon type="ios-keypad"></Icon>
              Item 2
            </MenuItem>
            <MenuItem name="3">
              <Icon type="ios-analytics"></Icon>
              Item 3
            </MenuItem>
            <MenuItem name="4">
              <Icon type="ios-paper"></Icon>
              Item 4
            </MenuItem>
          </div>
          -->
        </Menu>
      </Header>

      <Content :style="{padding: '0 50px'}">
        <!--<Breadcrumb :style="{margin: '20px 0'}">
          <BreadcrumbItem>Home</BreadcrumbItem>
          <BreadcrumbItem>Components</BreadcrumbItem>
          <BreadcrumbItem>Layout</BreadcrumbItem>
        </Breadcrumb>-->
        <el-row>
        <el-col :span="6">
            <el-input v-model="searchData" placeholder="输入姓名搜索">></el-input>
        </el-col>
        <el-col :span="2">
            <el-button type="success" @click="Search">搜索</el-button>
        </el-col>
        </el-row>
        <Card>
          <div style="min-height: 200px;">
            <v-table
              is-horizontal-resize
              style="width:100%"
              :columns="historyColumns"
              :table-data="historyData"
              row-hover-color="#eee"
              row-click-color="#edf7ff"
            ></v-table>
          </div>
        </Card>
      </Content>
      <div>
        <Page :total="dataCount" :page-size="pageSize" show-total  @on-change="changepage"></Page>
      </div>
    </Layout>
    </div>
  </div>
</template>

<script>
    let testData = {
        "histories": [

            {"username":"赵伟","email":"1210803358@qq.com","phone":"156*****1987"},
            {"username":"李伟","email":"1210803358@qq.com","phone":"182*****1538"},
            {"username":"孙伟","email":"1210803358@qq.com","phone":"161*****0097"},
            {"username":"周伟","email":"1210803358@qq.com","phone":"197*****1123"},
            {"username":"吴伟","email":"1210803358@qq.com","phone":"183*****6678"},
            {"username":"赵伟","email":"1210803358@qq.com","phone":"156*****1987"},
            {"username":"李伟","email":"1210803358@qq.com","phone":"182*****1538"},
            {"username":"孙伟","email":"1210803358@qq.com","phone":"161*****0097"},
            {"username":"周伟","email":"1210803358@qq.com","phone":"197*****1123"},
            {"username":"吴伟","email":"1210803358@qq.com","phone":"183*****6678"},
            {"username":"李伟","email":"1210803358@qq.com","phone":"182*****1538"},
            {"username":"孙伟","email":"1210803358@qq.com","phone":"161*****0097"},
            {"username":"周伟","email":"1210803358@qq.com","phone":"197*****1123"},
            {"username":"吴伟","email":"1210803358@qq.com","tel":"183*****6678"}
        ]
    }
    import LeftCommon from "./common/LeftCommon.vue"
    export default {
        components: {
           LeftCommon
        },
        data () {
            return {
                //搜索绑定
                searchData: "",

                ajaxHistoryData:[],
                // 初始化信息总条数
                dataCount:0,
                // 每页显示多少条
                pageSize:5,
                historyColumns: [
                    {field: 'username', title: '姓名', width: 80, titleAlign: 'center', columnAlign: 'center',isResize:true},
                    {field: 'email', title: '邮箱', width: 150, titleAlign: 'center', columnAlign: 'center',isResize:true},
                    {field: 'phone', title: '电话', width: 150, titleAlign: 'center', columnAlign: 'center',isResize:true},
                    {field: 'createTime', title: '创建时间', width: 150, titleAlign: 'center', columnAlign: 'center',isResize:true}

                ],
                historyData: []
            }
        },
        methods:{

            // 获取历史记录信息
            handleListApproveHistory(){
                debugger;
                var redirect = this;
                this.$axios.get('/userAll', {
                  })
                  .then(function (response) {

                      testData= response.data;
                      redirect.ajaxHistoryData = testData
                      redirect.dataCount = testData.length;
                      // 初始化显示，小于每页显示条数，全显，大于每页显示条数，取前每页条数显示
                      if(testData.length < redirect.pageSize){
                          redirect.historyData = redirect.ajaxHistoryData;
                      }else{
                          redirect.historyData = redirect.ajaxHistoryData.slice(0,redirect.pageSize);
                      }
                  })
                  .catch(function (response) {
                  });


            },
            changepage(index){

                var _start = ( index - 1 ) * this.pageSize;
                var _end = index * this.pageSize;
                this.historyData = this.ajaxHistoryData.slice(_start,_end);
            }
        },
        created(){
             this.handleListApproveHistory();
        },
        // 搜索过滤数据
        search(){
             alert("search");
             this.handleListApproveHistory();
        }
    }
</script>


<style scoped>
  .layout{
    border: 1px solid #d7dde4;
    background: #f5f7f9;
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    height: 100%;
  }
  .layout-logo{
    width: 100px;
    height: 30px;
    background: #5b6270;
    border-radius: 3px;
    float: left;
    position: relative;
    top: 15px;
    left: 20px;
    font-weight: bold;
    text-align: center;
    color: #49ffcc;
  }
  .layout-nav{
    width: 420px;
    margin: 0 auto;
    margin-right: 20px;
  }
  .layout-footer-center{
    text-align: center;
  }
</style>
